from SystematicFactors.General import Load_Systematic_Factor

# 获取无风险收益率
# TB1Y.WI 2015年开始
# Tbond_YTM_1Y 2002 年开始
def Get_Risk_Free_Data(database, datetime1, datetime2):
    #
    field_name = "TB1Y"
    df_rf = Load_Systematic_Factor(database, field_name, datetime1, datetime2)
    df_rf = df_rf[["date", field_name]].copy()

    # 无风险收益率数据整理
    df_rf[field_name] = df_rf[field_name] * 0.01
    df_rf.rename(columns={field_name:'rate'}, inplace=True)
    # df_rf['date'] = pd.to_datetime(df_rf['date'])
    df_rf = df_rf.dropna(axis=1, how='all')
    df_rf = df_rf.fillna(method='ffill').drop_duplicates() # 填补缺失值
    #
    return df_rf